package com.example.spring_mysql

import jakarta.validation.ConstraintValidator
import jakarta.validation.ConstraintValidatorContext

class NotZeroValidator : ConstraintValidator<NotZero, Number?> {
    override fun initialize(constraintAnnotation: NotZero?) {
        super.initialize(constraintAnnotation)
    }

    override fun isValid(value: Number?, context: ConstraintValidatorContext): Boolean {
        println("NotZeroValidator.isValid: ${value?.toInt() != 0}")
        if (value == null) {
            return false
        }

        if (value is Int) {
            return value.toInt() != 0
        }

        if (value is Long) {
            return value.toLong() != 0L
        }
        return true
    }
}
